        

        var shouldPayStore = new Ext.data.JsonStore({
			url: '/weihe/getList_shouldPay',
			root: 'datas',
			fields : [{
						name:'ShouldPayId',mapping:'id'
					},{
     				   name:'ShouldPayDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'ShouldPayType',mapping:'type'
					},{
						name:'ShouldPayName',mapping:'name'
					},{
						name:'ShouldPaySpay',mapping:'spay'
				    },{
				    	name:'ShouldPayContent',mapping:'content'
				    },{
				    	name:'ShouldPayDbalance',mapping:'dbalance',type: 'float'
				    },{
				    	name:'ShouldPayRbalance',mapping:'rbalance',type : 'float'
				    },{
				    	name:'ShouldPayClerk',mapping:'clerk'
				    },{
				    	name:'ShouldPayRemark',mapping:'remark'
				    },{
				    	name:'ShouldPayState',mapping:'state'
				    }],
				    baseParams : {'shouldPay.type': 'local'},
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_shouldPay',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
    	

shouldPays = function(){
	var tmp;
	
  return{
     
	  shouldPayGrid : function(){

		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 15,
			store : shouldPayStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		});

	

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		   

		
			
			
			   var linkButton = new Ext.Button({
				    text: '导出到Excel',
				    handler: function() {
					var config={store: null, title: '测试'};
						ExportExcel(shouldPayGrid,config);
			   		}
				});
			   
	
		   
		 
	   var shouldPayGrid = new Ext.grid.GridPanel({
		   id:'shouldPayGrid',
		   title : '国内(人民币)',
		   region : 'center',
		   minColumnWidth : 50,
		   tbar:["-",{
	   						text:"输入查询条件",
								handler:function(){
										shouldPays.infoWin().show();
								}
	   					},"-",{
	   						text:"查看全部",
								handler:function(){
									Ext.getCmp("shouldPayGrid").getStore().baseParams = {'flag': false,'shouldPay.type': 'local'};
									Ext.getCmp("shouldPayGrid").getStore().load({params : {start : 0, limit : 15}});
								}
	   			},"-",new Ext.Toolbar({
            buttons: [linkButton]
	   			})],

		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : shouldPayStore,
		   columns: [
		             {header : '单位名称', dataIndex : 'ShouldPayName',width:150},
		             {header : '应付账款', dataIndex : 'ShouldPaySpay'},
		             {header : '发生时间', dataIndex : 'ShouldPayDate', sortable : true,renderer:Ext.util.Format.dateRenderer('Y年m月d日')},
		             {header : '款项内容', dataIndex : 'ShouldPayContent'},
		             {header : '余额(人民币)', dataIndex : 'ShouldPayRbalance'},
		             {header : '余额(美金)', dataIndex : 'ShouldPayDbalance'},
		             {header : '业务员', dataIndex : 'ShouldPayClerk'},
		             {header : '备注', dataIndex : 'ShouldPayRemark'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   	   tmp = record.id;
				   Ext.getCmp("shouldPayForm").form.loadRecord(record);
				   Ext.getCmp("shouldPayForm").buttons[0].setText('修改');
			   }
		   
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return shouldPayGrid;
	},
	
	
	infoWin : function(){
  	  var infoWin = new Ext.Window({
  	  	id: 'receiInfo',
        title:'应付款查询',
        layout: 'fit',
        width:330,    
        height:250,
        modal: true,
        draggable : false,
        resizable: false,
        closeAction:"close",
        plain:true,    
        items:[shouldPays.queryForm()] 
        
    });  
  		return infoWin;
  	},
  	
  	queryForm : function(){
  		
  		
  	 var queryForm = new Ext.form.FormPanel({
			baseCls:"x-plain",
			frame : true,
			autoHeight : true,
			labelAlign : 'right',
			labelWidth : 85,
			defaultType : 'textfield',
				defaults : {
				width : 200
			},
			items : [{
					  fieldLabel: "单位名称",
      	    		  name: "shouldPay.name"
			 	  },{
					  fieldLabel: "业务员",
      	    		  name: "shouldPay.clerk"
			 	  },{
            		  xtype: 'datefield',
                      fieldLabel: "开始日期",
                      format : 'Y-m-d',
            		  name: "shouldPay.date"
				   },{
            		  xtype: 'datefield',
                      fieldLabel: "结束日期",
                      format : 'Y-m-d',
            		  name: 'shouldPay.endDate'
				   }],
			buttons:[{
        		 text:'确认',
             	 handler:function(){
             	 	var name = queryForm.form.findField('shouldPay.name').getValue()
             	 	var clerk = queryForm.form.findField('shouldPay.clerk').getValue()
             	 	var date = queryForm.form.findField('shouldPay.date').getValue();
             	 	var endDate = queryForm.form.findField('shouldPay.endDate').getValue();
				 Ext.getCmp("shouldPayGrid").getStore().baseParams = {'flag': true,'shouldPay.name':name,
					 													  'shouldPay.clerk':clerk,
					 													  'shouldPay.date':date,
					 													  'shouldPay.endDate':endDate,
					 													  'shouldPay.type': 'local'};
				 Ext.getCmp("shouldPayGrid").getStore().load({params : {start : 0, limit : 15}});
				 queryForm.form.reset();
                 Ext.getCmp("receiInfo").close();
              	
              	}
              },{
                 text:'取消',
                 handler:function(){
                 	queryForm.form.reset();
                 	Ext.getCmp("receiInfo").close();
                 }
              }]   
        });
        return queryForm;
  	
  	}
  }
}();








